package com.shen.eduorder.service.impl;

import com.shen.commonutils.ordervo.CourseWebVoOrder;
import com.shen.commonutils.ordervo.UcenterMemberOrder;
import com.shen.eduorder.client.EduClient;
import com.shen.eduorder.client.UcenterClient;
import com.shen.eduorder.entity.TOrder;
import com.shen.eduorder.mapper.TOrderMapper;
import com.shen.eduorder.service.TOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shen.eduorder.util.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author shenkaituo
 * @since 2020-07-08
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {

    @Autowired
    EduClient eduClient;
    @Autowired
    UcenterClient ucenterClient;
    @Override
    public String createOrders(String courseId, String userId) {
        //通过远程调用 获取到课程信息和用户信息
        CourseWebVoOrder courseInfo = eduClient.getCourseInfoOrder(courseId);

        UcenterMemberOrder userInfo = ucenterClient.getUserInfoOrder(userId);
        // 创建order对象 设置order对象的值
        TOrder order=new TOrder();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfo.getTitle());
        order.setCourseCover(courseInfo.getCover());
        order.setTeacherName(courseInfo.getTeacherName());
        order.setTotalFee(courseInfo.getPrice());
        order.setMemberId(userId);
        order.setMobile(userInfo.getMobile());

        order.setNickname(userInfo.getNickname());
        order.setStatus(0);//0未支付
        order.setPayType(1); //支付类型 微信1

        /////////////////////////////////////
        System.out.println("courseInfo----.....>>>>>"+courseInfo);
        System.out.println("userInfo----.....>>>>>"+userInfo);
        //baseMapper.insert(order);
        System.out.println("order------------------->"+order);
        ///////////////////
        Date date=new Date();
        order.setGmtCreate(date);
        order.setGmtModified(date);

        baseMapper.insert(order);
        return order.getOrderNo();

    }
}
